package com.jwthhealth_pub.old.individual.view.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.individual.module.HeartData;
import com.jwthhealth_pub.old.individual.view.IndividualHeartActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/3/24.
 */


public class HeartAdapter extends RecyclerView.Adapter {

    @BindView(R.id.clicklayout)
    RelativeLayout clicklayout;
    private IndividualHeartActivity activity;
    private final List<HeartData.DataBean.ListBean> list;

    public HeartAdapter(IndividualHeartActivity individualHeartActivity, HeartData.DataBean data) {
        this.activity = individualHeartActivity;
        this.list = data.getList();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(activity, R.layout.item_heart, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        final HeartData.DataBean.ListBean listBean = list.get(position);
        viewHolder.dateValue.setText(listBean.getShowtime());
        viewHolder.clicklayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                activity.refreshUI(listBean);
                activity.refreshUi();
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.date_value)
        TextView dateValue;
        @BindView(R.id.clicklayout)
        RelativeLayout clicklayout;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
